import { InnerMineEntity, SpawnEntity } from "GameLoop/WorldState/EntityManager/Entitys";
import { State } from "framework/FSM/AState";
import { ActionArgHelper } from "../../../ActionManager/ActionArgHelper";



/**填充任务
 * 从spawn模块 或者是 core模块，取能量填充。填满
 */ 
export class FillTask<T extends IStateArg<Creep>>  extends State<T>
{
    /**
     *  
     * @param arg 
     */
    public  getActions(arg:T):Action[]
    {
       
        const creep = arg.entity;
        if(!creep.memory.taskid)
        {

            return []
        }
        const task =arg.task as ITask<ICreepTaskData<"fill">>;
        if(!task)
        {
            return []
        }
        // 搬运工
        
        // 检测
        if(creep.store.getUsedCapacity()==0)
        {
            creep.memory.state = 0;

        }
        else   
        {
            // 有能量就可以去填充了
            creep.memory.state = 1;
            // 绝不空载
        }
        if(creep.memory.state)
        {
            return [ActionArgHelper.actionMoveFill(creep,task.data.arg.targets)];
        }
        else
        {
            const obj = creep.room.getResourceObject("filltask",creep);
            if(obj)
            {
                return [ActionArgHelper.actionWithdraw(creep,obj.object as AnyStoreStructure,[{resourceType:RESOURCE_ENERGY}])];
            }
            else 
            {
                if(creep.room.getResource(RESOURCE_ENERGY).length)
                {
                    return [ActionArgHelper.actionPickup(creep,creep.room.getResource(RESOURCE_ENERGY)[0] )];
                }
            }
            // if(!creep.memory.sourceId)
            // {
            //     const obj = creep.room.getResourceObject("filltask",creep);
            //     if(obj)
            //     {
            //         creep.memory.sourceId = obj.object.id;
            //     }
            // }
            // if(creep.memory.sourceId)
            // {
            //     const store = Game.getObjectById(creep.memory.sourceId) as AnyStoreStructure;
            //     if(store && store.store.getUsedCapacity(RESOURCE_ENERGY)>0)
            //     {
            //         return [ActionArgHelper.actionWithdraw(creep,store,[{resourceType:RESOURCE_ENERGY}])];
            //     }
            //     creep.memory.sourceId=undefined;
            // }
            
        }
        return [ ];
    }
}
